import { getBannerListReq } from '@/service/banner'
import { Effect, ImmerReducer } from 'umi'
import { IBanner } from '../banner'
export interface IBannerState {
    bannerList: Array<IBanner>
}

export interface IBannerModel {
    namespace: 'banner',
    state: IBannerState,
    effects: {
      getBannerListEffect: Effect
    },
    reducers: {
      UPDATE_BANNER_LIST: ImmerReducer
    }
}

const bannerModel: IBannerModel = {
    namespace: 'banner',
    state: {
        bannerList:[]
    },
    effects:{
        *getBannerListEffect({payload},{call,put}){
            const res = yield call(getBannerListReq,payload)
            yield put({
                type:'UPDATE_BANNER_LIST',
                payload: res.data
            })
        }
    },
    reducers: {
        UPDATE_BANNER_LIST(state,action){
            state.bannerList = action.payload
        }
    }
}

export default bannerModel